//
//  AuthorCertificationCustomAddressActionSheet.m
//  Yanwei
//
//  Created by Seven-Augus on 2017/5/5.
//  Copyright © 2017年 DCloud. All rights reserved.
//

#define AuthorCCustomAddressASButtonColor RGBACOLOR(44, 44, 44, 1)

#import "AuthorCertificationCustomAddressActionSheet.h"
#import "MuchStoreRequestManager.h"
//#import "StoreProvinceAOtherModel.h"

@interface AuthorCertificationCustomAddressActionSheet () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UIView *authorCCustomAddressASTopBgView; // 顶部视图
@property (nonatomic, strong) UIView *authorCCustomAddressASBottomLineView; // 顶部视图分隔线
@property (nonatomic, strong) UIButton *authorCCustomAddressASProvinceButton; // 省按钮
@property (nonatomic, strong) UIButton *authorCCustomAddressASCityButton; // 市按钮
@property (nonatomic, strong) UIButton *authorCCustomAddressASDistrictButton; // 区按钮
@property (nonatomic, strong) UIView *authorCCustomAddressASProvinceButtonLine; // 省按钮线
@property (nonatomic, strong) UIView *authorCCustomAddressASCityButtonLine; // 市按钮线
@property (nonatomic, strong) UIView *authorCCustomAddressASDistrictButtonLine; // 区按钮线
@property (nonatomic, strong) UIButton *authorCCustomAddressASSureButton; // 确认按钮
@property (nonatomic, strong) UITableView *authorCCustomAddressASTableView; // 地址表格视图
@property (nonatomic, assign) NSInteger addressArrayCount; // 地址数量
@property (nonatomic, assign) NSInteger provinceIndex; // 省
@property (nonatomic, assign) NSInteger cityIndex; // 市
@property (nonatomic, assign) NSInteger districtIndex; // 区
@property (nonatomic, assign) NSInteger nowAddressButonTag; // 当前地址按钮Tag
@property (nonatomic, assign) NSInteger nowProvinceSelectedCell; // 当前省选中的Cell
@property (nonatomic, assign) NSInteger nowCitySelectedCell; // 当前市选中的Cell
@property (nonatomic, assign) NSInteger nowDistrictSelectedCell; // 当前区选中的Cell
@property (nonatomic, strong) NSMutableArray *provinceDataSourceArray; // 省数据数组
@property (nonatomic, strong) NSMutableArray *cityDataSourceArray; // 市数据数组
@property (nonatomic, strong) NSMutableArray *distractDataSourceArray; // 区数据数组
@property (nonatomic, assign) NSInteger isAddressChangeSection; // 地址改变
@property (nonatomic, strong) UIButton *currentButton; // 当前按钮
@property (nonatomic, strong) NSString *areaSidString;
@property (nonatomic, strong) NSString *distractEndString;

@end

@implementation AuthorCertificationCustomAddressActionSheet

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.frame = CGRectMake(0, 0, ScreenWidth, 350);
        self.backgroundColor = [UIColor whiteColor];
        // 初始化视图
        [self initView];
        // 初始化数据
        [self initDataSource];
    }
    return self;
}

/** 初始化视图 */
- (void)initView {
    self.authorCCustomAddressASTopBgView.backgroundColor = [UIColor whiteColor];
}

/** 初始化数据 */
- (void)initDataSource {
    self.nowProvinceSelectedCell = 1000;
    self.nowCitySelectedCell = 1000;
    self.nowDistrictSelectedCell = 1000;
}

#pragma mark - <UITableViewDelegate, UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.addressArrayCount;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"authorCCustomAStableViewCellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.textLabel.textAlignment = NSTextAlignmentLeft;
        cell.textLabel.font = APPFONT(15);
    }
    
    return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.nowProvinceSelectedCell == 1000 ) {
        self.authorCCustomAddressASCityButton.userInteractionEnabled = NO;
    } else {
        self.authorCCustomAddressASCityButton.userInteractionEnabled = YES;
    }
    if (self.nowCitySelectedCell == 1000) {
        _authorCCustomAddressASDistrictButton.userInteractionEnabled = NO;
    } else {
        _authorCCustomAddressASDistrictButton.userInteractionEnabled = YES;
    }
    
    if (self.nowAddressButonTag == AuthorCCustomAddressASProvinceButtonType) {
        [self changeAddressSelectedTitleColor:cell SelectedCell:self.nowProvinceSelectedCell IndexPath:indexPath];
        ProvinceModel *storeProvinceModel = _provinceDataSourceArray[indexPath.row];
        cell.textLabel.text = storeProvinceModel.name;
    }
    if (self.nowAddressButonTag == AuthorCCustomAddressASCityButtonType) {
        [self changeAddressSelectedTitleColor:cell SelectedCell:self.nowCitySelectedCell IndexPath:indexPath];
        ProvinceModel *storeProvinceModel = _cityDataSourceArray[indexPath.row];
        cell.textLabel.text = storeProvinceModel.name;
    }
    if (self.nowAddressButonTag == AuthorCCustomAddressASDistrictButtonType) {
        [self changeAddressSelectedTitleColor:cell SelectedCell:self.nowDistrictSelectedCell IndexPath:indexPath];
        ProvinceModel *storeProvinceModel = _distractDataSourceArray[indexPath.row];
        cell.textLabel.text = storeProvinceModel.name;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (self.nowAddressButonTag) {
        case AuthorCCustomAddressASProvinceButtonType:
            if (_provinceDataSourceArray.count != 0) {
                if (indexPath.row != self.nowProvinceSelectedCell) {
                    ProvinceModel *storeProvinceModel = _provinceDataSourceArray[indexPath.row];
                    [self changeAddressButtonTitle:self.authorCCustomAddressASProvinceButton ButtonTitle:storeProvinceModel.name];
                    self.areaSidString = storeProvinceModel.sid;
                    [self.authorCCustomAddressASCityButton setTitle:@"城市" forState:UIControlStateNormal];
                    [_authorCCustomAddressASDistrictButton setTitle:@"区" forState:UIControlStateNormal];
                    self.nowCitySelectedCell = 1000;
                    self.nowDistrictSelectedCell = 1000;
                }
                self.provinceIndex = indexPath.row;
                self.nowProvinceSelectedCell = indexPath.row;
                
                [self progressAuthorCCustomAddressASButton:self.authorCCustomAddressASCityButton];
            }
            break;
        case AuthorCCustomAddressASCityButtonType:
            if (_cityDataSourceArray.count != 0) {
                if (indexPath.row != self.nowCitySelectedCell) {
                    ProvinceModel *storeProvinceModel = _cityDataSourceArray[indexPath.row];
                    [self changeAddressButtonTitle:self.authorCCustomAddressASCityButton ButtonTitle:storeProvinceModel.name];
                    self.areaSidString = storeProvinceModel.sid;
                    [_authorCCustomAddressASDistrictButton setTitle:@"区" forState:UIControlStateNormal];
                    self.nowDistrictSelectedCell = 1000;
                }
                self.cityIndex = indexPath.row;
                self.nowCitySelectedCell = indexPath.row;
                if (_isContainsDistrict) {
                    [self progressAuthorCCustomAddressASButton:self.authorCCustomAddressASDistrictButton];
                } else {
                    [self.authorCCustomAddressASTableView reloadData];
                }
            }
            break;
        case AuthorCCustomAddressASDistrictButtonType:
            if (_distractDataSourceArray.count != 0) {
                [self setDistrictButtonTitle:indexPath];
                [self.authorCCustomAddressASTableView reloadData];
            }
            break;
        default:
            break;
    }
}
- (void)setDistrictButtonTitle:(NSIndexPath *)indexPath {
    ProvinceModel *storeProvinceModel = _distractDataSourceArray[indexPath.row];
    NSLog(@"_authorCCustomAddressASDistrictButton.frame == %@", _authorCCustomAddressASDistrictButton);
    
    // 自适应宽
    NSDictionary *attrs = @{NSFontAttributeName:APPFONT(15)};
    NSString *autoString = storeProvinceModel.name;
    CGSize size = [autoString sizeWithAttributes:attrs];
    CGFloat singleStringWidth = size.width / autoString.length;
    CGFloat sureButtonWidth = ScreenWidth - _authorCCustomAddressASSureButton.frame.origin.x;
    CGFloat districtButtonWidth = ScreenWidth - _authorCCustomAddressASDistrictButton.frame.origin.x - sureButtonWidth;
    NSString *endString;
    NSInteger endAutoSub = 0;
    CGFloat endSingleStringWidth;

    CGFloat maxWidth = districtButtonWidth - 20;
    for (int i = 0; i < autoString.length; i ++) {
        endSingleStringWidth = singleStringWidth *i;
        if (maxWidth > endSingleStringWidth) {
            endString = [autoString substringToIndex:i +1];
            endAutoSub = i;
        } else {
            endString = [[endString substringToIndex:endAutoSub] stringByAppendingString:@"..."];
        }
    }
    
    self.distractEndString = storeProvinceModel.name;
    [self changeAddressButtonTitle:_authorCCustomAddressASDistrictButton ButtonTitle:endString];
    self.areaSidString = storeProvinceModel.sid;
    self.nowDistrictSelectedCell = indexPath.row;
}

#pragma mark - method
- (void)changeAddressButtonTitle:(UIButton *)sender ButtonTitle:(NSString *)buttonTitle {
    [sender setTitle:buttonTitle forState:UIControlStateNormal];
}
- (void)changeAddressSelectedTitleColor:(UITableViewCell *)cell SelectedCell:(NSInteger)selectedCell IndexPath:(NSIndexPath *)indexPath {
    if (selectedCell == indexPath.row) {
        cell.textLabel.textColor = Color175030;
    } else {
        cell.textLabel.textColor = AuthorCCustomAddressASButtonColor;
    }
}

/** 地址 */
- (void)addressMethod {
    // 获取省数据
    [self getProvinceValueHTTP];
}
/** 初始数据 */
- (void)setAddressValue {
    self.addressArrayCount = [_provinceDataSourceArray count];
    switch (self.currentButton.tag) {
        case AuthorCCustomAddressASProvinceButtonType:
            self.addressArrayCount = [_provinceDataSourceArray count];
            break;
        case AuthorCCustomAddressASCityButtonType:
            self.addressArrayCount = [_cityDataSourceArray count];
            break;
        case AuthorCCustomAddressASDistrictButtonType:
            self.addressArrayCount = [_distractDataSourceArray count];
            break;
    }
    if (_isAddressChangeSection == 0) {
        [self isTimeRoAddressString:@"省份" CityString:@"城市" DistrictString:@"区"];
    }
    _isAddressChangeSection = 1;
    
    [self.authorCCustomAddressASTableView setContentOffset:CGPointMake(0,0) animated:NO];
    [self.authorCCustomAddressASTableView reloadData];
}
/** 获取省数据 */
- (void)getProvinceValueHTTP {
    [MuchStoreRequestManager storeGetProvinceList:^(NSMutableArray *data) {
        if (data.count > 0) {
            self.provinceDataSourceArray = data;
            [self setAddressValue];
        }
    } fail:^(NSString *error) {}];
}

/** 获取市数据 */
- (void)getCityValueHTTP {
    ProvinceModel *storeProvinceModel = _provinceDataSourceArray[self.provinceIndex];
    [MuchStoreRequestManager storeGetCityList:storeProvinceModel.sid success:^(NSMutableArray *data) {
        if (data.count > 0) {
            self.cityDataSourceArray = data;
            [self setAddressValue];
        }
    } fail:^(NSString *error) {}];
}

/** 获取区数据 */
- (void)getDistrictValueHTTP {
    ProvinceModel *storeProvinceModel = _cityDataSourceArray[self.cityIndex];
    [MuchStoreRequestManager storeGetDistrictList:storeProvinceModel.sid success:^(NSMutableArray *data) {
        if (data.count > 0) {
            self.distractDataSourceArray = data;
            [self setAddressValue];
        }
    } fail:^(NSString *error) {}];
}

- (void)reloadTableViewList:(AuthorCertificationCustomAddressActionSheetButtonType)type {
    switch (type) {
        case AuthorCCustomAddressASProvinceButtonType:
            _provinceDataSourceArray = nil;
            _cityDataSourceArray = nil;
            _distractDataSourceArray = nil;
            break;
        case AuthorCCustomAddressASCityButtonType:
            _cityDataSourceArray = nil;
            _distractDataSourceArray = nil;
            break;
        case AuthorCCustomAddressASDistrictButtonType:
            _distractDataSourceArray = nil;
            break;
        default:
            break;
    }
    [self.authorCCustomAddressASTableView reloadData];
}


#pragma mark - progress
- (void)progressAuthorCCustomAddressASButton:(UIButton *)sender {
    switch (sender.tag) {
        case AuthorCCustomAddressASProvinceButtonType:
            [self reloadTableViewList:AuthorCCustomAddressASProvinceButtonType];
            [self getProvinceValueHTTP];
            self.currentButton = sender;
            break;
        case AuthorCCustomAddressASCityButtonType:
            [self reloadTableViewList:AuthorCCustomAddressASCityButtonType];
            [self getCityValueHTTP];
            self.currentButton = sender;
            break;
        case AuthorCCustomAddressASDistrictButtonType:
            [self reloadTableViewList:AuthorCCustomAddressASDistrictButtonType];
            [self getDistrictValueHTTP];
            self.currentButton = sender;
            break;
        case AuthorCCustomAddressASSureButtonType:
            if (_isContainsDistrict) {
                if (self.nowProvinceSelectedCell == 1000 || self.nowCitySelectedCell == 1000 || self.nowDistrictSelectedCell == 1000) {
                    [SVProgressHUD dismiss];
                    [SVProgressHUD showErrorWithStatus:@"请选择省市区！"];
                } else {
                    [self hideView];
                    [self removeFromSuperview];
                    if ([self.delegate respondsToSelector:@selector(getAuthorCertificationCustomAddressActionSheetString:areaSid:)]) {
                        NSString * address = [NSString stringWithFormat:@"%@-%@-%@", self.authorCCustomAddressASProvinceButton.titleLabel.text, self.authorCCustomAddressASCityButton.titleLabel.text, self.distractEndString];
                        [self.delegate getAuthorCertificationCustomAddressActionSheetString:address areaSid:self.areaSidString];
                    }
                }
            } else {
                if (self.nowProvinceSelectedCell == 1000 || self.nowCitySelectedCell == 1000) {
                    [SVProgressHUD dismiss];
                    [SVProgressHUD showErrorWithStatus:@"请选择省市！"];
                } else {
                    [self hideView];
                    [self removeFromSuperview];
                    if ([self.delegate respondsToSelector:@selector(getAuthorCertificationCustomAddressActionSheetString:areaSid:)]) {
                        [self.delegate getAuthorCertificationCustomAddressActionSheetString:[[self.authorCCustomAddressASProvinceButton.titleLabel.text stringByAppendingString:@"-"] stringByAppendingString:self.authorCCustomAddressASCityButton.titleLabel.text] areaSid:self.areaSidString];
                    }
                }
            }
            break;
        default:
            break;
    }
    if (sender.tag != AuthorCCustomAddressASSureButtonType) {
        [self changeAuthorCCustomAddressASButtonLineFrame:sender];
    }
}
/** 改变按钮线的位置 */
- (void)changeAuthorCCustomAddressASButtonLineFrame:(UIButton *)sender {
    self.nowAddressButonTag = sender.tag;
    switch (sender.tag) {
        case AuthorCCustomAddressASProvinceButtonType:
            self.authorCCustomAddressASProvinceButtonLine.backgroundColor = Color175030;
            self.authorCCustomAddressASCityButtonLine.backgroundColor = [UIColor clearColor];
            _authorCCustomAddressASDistrictButtonLine.backgroundColor = [UIColor clearColor];
            break;
        case AuthorCCustomAddressASCityButtonType:
            self.authorCCustomAddressASProvinceButtonLine.backgroundColor = [UIColor clearColor];
            self.authorCCustomAddressASCityButtonLine.backgroundColor = Color175030;
            _authorCCustomAddressASDistrictButtonLine.backgroundColor = [UIColor clearColor];
            break;
        case AuthorCCustomAddressASDistrictButtonType:
            self.authorCCustomAddressASProvinceButtonLine.backgroundColor = [UIColor clearColor];
            self.authorCCustomAddressASCityButtonLine.backgroundColor = [UIColor clearColor];
            _authorCCustomAddressASDistrictButtonLine.backgroundColor = Color175030;
            break;
        default:
            break;
    }
}


#pragma mark - setting
- (void)setIsContainsDistrict:(BOOL)isContainsDistrict {
    _isContainsDistrict = isContainsDistrict;
    [self addressMethod];
}

- (void)isTimeRoAddressString:(NSString *)provinceString CityString:(NSString *)cityString DistrictString:(NSString *)districtString {
    [self.authorCCustomAddressASProvinceButton setTitle:provinceString forState:UIControlStateNormal];
    [self.authorCCustomAddressASCityButton setTitle:cityString forState:UIControlStateNormal];
    if (_isContainsDistrict) { // 有区
        [self.authorCCustomAddressASDistrictButton setTitle:districtString forState:UIControlStateNormal];
        self.authorCCustomAddressASDistrictButtonLine.backgroundColor = [UIColor clearColor];
    }
}


#pragma mark - 懒加载
- (UIView *)authorCCustomAddressASTopBgView {
    if (!_authorCCustomAddressASTopBgView) {
        _authorCCustomAddressASTopBgView = [UIView new];
        [self addSubview:_authorCCustomAddressASTopBgView];
        [_authorCCustomAddressASTopBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.left.and.right.equalTo(self);
            make.height.mas_equalTo(39);
        }];
        self.authorCCustomAddressASBottomLineView.backgroundColor = Color217;
        [self.authorCCustomAddressASProvinceButton setTitle:@"省份" forState:UIControlStateNormal];
        [self.authorCCustomAddressASCityButton setTitle:@"城市" forState:UIControlStateNormal];
        
        [self.authorCCustomAddressASSureButton setTitle:@"确定" forState:UIControlStateNormal];
        
        self.authorCCustomAddressASProvinceButtonLine.backgroundColor = Color175030;
        self.authorCCustomAddressASCityButtonLine.backgroundColor = [UIColor clearColor];
    }
    return _authorCCustomAddressASTopBgView;
}
- (UIView *)authorCCustomAddressASBottomLineView {
    if (!_authorCCustomAddressASBottomLineView) {
        _authorCCustomAddressASBottomLineView = [UIView new];
        [self addSubview:_authorCCustomAddressASBottomLineView];
        [_authorCCustomAddressASBottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.authorCCustomAddressASTopBgView.mas_bottom);
            make.left.and.right.equalTo(self.authorCCustomAddressASTopBgView);
            make.height.mas_equalTo(1);
        }];
    }
    return _authorCCustomAddressASBottomLineView;
}
- (UIButton *)authorCCustomAddressASProvinceButton {
    if (!_authorCCustomAddressASProvinceButton) {
        _authorCCustomAddressASProvinceButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _authorCCustomAddressASProvinceButton.titleLabel.font = APPFONT(15);
        [_authorCCustomAddressASProvinceButton setTitleColor:AuthorCCustomAddressASButtonColor forState:UIControlStateNormal];
        _authorCCustomAddressASProvinceButton.tag = AuthorCCustomAddressASProvinceButtonType;
        [_authorCCustomAddressASProvinceButton addTarget:self action:@selector(progressAuthorCCustomAddressASButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.authorCCustomAddressASTopBgView addSubview:_authorCCustomAddressASProvinceButton];
        [_authorCCustomAddressASProvinceButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.authorCCustomAddressASTopBgView);
            make.bottom.equalTo(self.authorCCustomAddressASTopBgView).with.offset(-3);
            make.left.equalTo(self.authorCCustomAddressASTopBgView).with.offset(15);
        }];
    }
    return _authorCCustomAddressASProvinceButton;
}
- (UIButton *)authorCCustomAddressASCityButton {
    if (!_authorCCustomAddressASCityButton) {
        _authorCCustomAddressASCityButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _authorCCustomAddressASCityButton.titleLabel.font = APPFONT(15);
        [_authorCCustomAddressASCityButton setTitleColor:AuthorCCustomAddressASButtonColor forState:UIControlStateNormal];
        _authorCCustomAddressASCityButton.tag = AuthorCCustomAddressASCityButtonType;
        [_authorCCustomAddressASCityButton addTarget:self action:@selector(progressAuthorCCustomAddressASButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.authorCCustomAddressASTopBgView addSubview:_authorCCustomAddressASCityButton];
        [_authorCCustomAddressASCityButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.bottom.equalTo(self.authorCCustomAddressASProvinceButton);
            make.left.equalTo(self.authorCCustomAddressASProvinceButton.mas_right).with.offset(15);
        }];
    }
    return _authorCCustomAddressASCityButton;
}
- (UIButton *)authorCCustomAddressASSureButton {
    if (!_authorCCustomAddressASSureButton) {
        _authorCCustomAddressASSureButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _authorCCustomAddressASSureButton.titleLabel.font = APPFONT(15);
        [_authorCCustomAddressASSureButton setTitleColor:AuthorCCustomAddressASButtonColor forState:UIControlStateNormal];
        _authorCCustomAddressASSureButton.tag = AuthorCCustomAddressASSureButtonType;
        [_authorCCustomAddressASSureButton addTarget:self action:@selector(progressAuthorCCustomAddressASButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.authorCCustomAddressASTopBgView addSubview:_authorCCustomAddressASSureButton];
        [_authorCCustomAddressASSureButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.bottom.equalTo(self.authorCCustomAddressASCityButton);
            make.right.equalTo(self.authorCCustomAddressASTopBgView.mas_right).with.offset(- 15);
        }];
    }
    return _authorCCustomAddressASSureButton;
}
- (UIButton *)authorCCustomAddressASDistrictButton {
    if (!_authorCCustomAddressASDistrictButton) {
        _authorCCustomAddressASDistrictButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _authorCCustomAddressASDistrictButton.titleLabel.font = APPFONT(15);
        [_authorCCustomAddressASDistrictButton setTitleColor:AuthorCCustomAddressASButtonColor forState:UIControlStateNormal];
        _authorCCustomAddressASDistrictButton.tag = AuthorCCustomAddressASDistrictButtonType;
        [_authorCCustomAddressASDistrictButton addTarget:self action:@selector(progressAuthorCCustomAddressASButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.authorCCustomAddressASTopBgView addSubview:_authorCCustomAddressASDistrictButton];
        [_authorCCustomAddressASDistrictButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.bottom.equalTo(self.authorCCustomAddressASCityButton);
            make.left.equalTo(self.authorCCustomAddressASCityButton.mas_right).with.offset(15);
        }];
    }
    return _authorCCustomAddressASDistrictButton;
}
- (UITableView *)authorCCustomAddressASTableView {
    if (!_authorCCustomAddressASTableView) {
        _authorCCustomAddressASTableView = [UITableView new];
        _authorCCustomAddressASTableView.delegate = self;
        _authorCCustomAddressASTableView.dataSource = self;
        _authorCCustomAddressASTableView.estimatedRowHeight = 0;
        _authorCCustomAddressASTableView.estimatedSectionHeaderHeight = 0;
        _authorCCustomAddressASTableView.estimatedSectionFooterHeight = 0;
        _authorCCustomAddressASTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self addSubview:_authorCCustomAddressASTableView];
        [_authorCCustomAddressASTableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.authorCCustomAddressASBottomLineView.mas_bottom);
            make.left.and.right.and.bottom.equalTo(self);
        }];
    }
    return _authorCCustomAddressASTableView;
}
- (UIView *)authorCCustomAddressASProvinceButtonLine {
    if (!_authorCCustomAddressASProvinceButtonLine) {
        _authorCCustomAddressASProvinceButtonLine = [UIView new];
        [_authorCCustomAddressASTopBgView addSubview:_authorCCustomAddressASProvinceButtonLine];
        [_authorCCustomAddressASProvinceButtonLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.authorCCustomAddressASProvinceButton);
            make.top.equalTo(self.authorCCustomAddressASProvinceButton.mas_bottom);
            make.bottom.equalTo(self.authorCCustomAddressASTopBgView);
            make.width.equalTo(self.authorCCustomAddressASProvinceButton);
        }];
    }
    return _authorCCustomAddressASProvinceButtonLine;
}
- (UIView *)authorCCustomAddressASCityButtonLine {
    if (!_authorCCustomAddressASCityButtonLine) {
        _authorCCustomAddressASCityButtonLine = [UIView new];
        [_authorCCustomAddressASTopBgView addSubview:_authorCCustomAddressASCityButtonLine];
        [_authorCCustomAddressASCityButtonLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.authorCCustomAddressASCityButton);
            make.top.equalTo(self.authorCCustomAddressASCityButton.mas_bottom);
            make.bottom.equalTo(self.authorCCustomAddressASTopBgView);
            make.width.equalTo(self.authorCCustomAddressASCityButton);
        }];
    }
    return _authorCCustomAddressASCityButtonLine;
}
- (UIView *)authorCCustomAddressASDistrictButtonLine {
    if (!_authorCCustomAddressASDistrictButtonLine) {
        _authorCCustomAddressASDistrictButtonLine = [UIView new];
        [_authorCCustomAddressASTopBgView addSubview:_authorCCustomAddressASDistrictButtonLine];
        [_authorCCustomAddressASDistrictButtonLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.authorCCustomAddressASDistrictButton);
            make.top.equalTo(self.authorCCustomAddressASDistrictButton.mas_bottom);
            make.bottom.equalTo(self.authorCCustomAddressASTopBgView);
            make.width.equalTo(self.authorCCustomAddressASDistrictButton);
        }];
    }
    return _authorCCustomAddressASDistrictButtonLine;
}
- (NSInteger)addressArrayCount {
    return MAX(0, _addressArrayCount);
}
- (NSInteger)provinceIndex {
    return MAX(0, _provinceIndex);
}
- (NSInteger)cityIndex {
    return MAX(0, _cityIndex);
}
- (NSInteger)districtIndex {
    return MAX(0, _districtIndex);
}
- (NSInteger)nowAddressButonTag {
    return MAX(AuthorCCustomAddressASProvinceButtonType, _nowAddressButonTag);
}
- (NSInteger)nowProvinceSelectedCell {
    return MAX(0, _nowProvinceSelectedCell);
}
- (NSInteger)nowCitySelectedCell {
    return MAX(0, _nowCitySelectedCell);
}
- (NSInteger)nowDistrictSelectedCell {
    return MAX(0, _nowDistrictSelectedCell);
}
- (NSMutableArray *)provinceDataSourceArray {
    if (!_provinceDataSourceArray) {
        _provinceDataSourceArray = [[NSMutableArray alloc] init];
    }
    return _provinceDataSourceArray;
}
- (NSMutableArray *)cityDataSourceArray {
    if (!_cityDataSourceArray) {
        _cityDataSourceArray = [[NSMutableArray alloc] init];
    }
    return _cityDataSourceArray;
}
- (NSMutableArray *)distractDataSourceArray {
    if (!_distractDataSourceArray) {
        _distractDataSourceArray = [[NSMutableArray alloc] init];
    }
    return _distractDataSourceArray;
}

@end
